home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / GDEVLN03.C < prev    next >
C/C++ Source or Header  |  1991-11-24  |  5KB  |  148 lines

  1. /* Copyright (C) 1991 Free Software Foundation, Inc.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /*
  20. gdevln03.c
  21. Ghostscript driver for DEC LN03 printer
  22.  
  23. Ulrich Mueller, Div. PPE, CERN, CH-1211 Geneva 23 <ulm@vsnhd1.cern.ch>
  24. This code is subject to the GNU General Public License
  25.  
  26. ulm 91-02-13 created as driver for gs 2.1.1
  27. ulm 91-07-23 adapted to gs 2.2
  28. ulm 91-08-21 changed memory allocation to gs_malloc,
  29.          ported to VMS (contributed by Martin Stiftinger, TU Vienna)
  30. lpd 91-11-24 sped up by removing multiplies from inner loop
  31. */
  32.  
  33. #include "gdevprn.h"
  34.  
  35. /* The device descriptor */
  36. private dev_proc_print_page(ln03_print_page);
  37. gx_device_printer gs_ln03_device =
  38.     prn_device(prn_std_procs, "ln03",
  39.            82,            /* width_10ths,  2460 pixel */
  40.            115,            /* height_10ths, 3450 pixel */
  41.            300, 300,        /* x_dpi, y_dpi */
  42.            0, 0.3, 0, 0,        /* margins */
  43.            1, ln03_print_page);
  44.  
  45. /* ------ Internal routines ------ */
  46.  
  47. /* Send the page to the printer. */
  48. private int
  49. ln03_print_page(gx_device_printer *pdev, FILE *prn_stream)
  50. {
  51.     byte *in, *inp;
  52.     int lnum, lcount, l, count, empty, mask, c, oldc, line_size, in_size;
  53.  
  54.     line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  55.     in_size = line_size * 6;
  56.     in = (byte *)gs_malloc(in_size, 1, "ln03_print_page");
  57.  
  58.     /* Check allocation */
  59.     if (!in) return(-1);
  60.  
  61.     /* switch to graphics mode, 300 dpi
  62.        <ESC>[!p        DECSTR    soft terminal reset
  63.        <ESC>[11h    PUM    select unit of measurement
  64.        <ESC>[7 I    SSU    select pixel as size unit
  65.        <ESC>[?52h    DECOPM    origin is upper-left corner
  66.        <ESC>[3475t    DECSLPP    form length (3475 pixels)
  67.        <ESC>[0;2460s    DECSLRM    left and right margins (0, 2460 pixels)
  68.        <ESC>P0;0;1q        select sixel graphics mode
  69.        "1;1        DECGRA    aspect ratio (1:1)
  70.        *** Parameters are for A4 paper format.
  71.        *** Could someone please check them for american paper format? */
  72.     fputs(
  73.       "\033[!p\033[11h\033[7 I\033[?52h\033[3475t\033[0;2460s\033P0;0;1q\"1;1",
  74.       prn_stream);
  75.  
  76.     /* Print lines of graphics */
  77.     for (lnum = lcount = 0; lnum < pdev->height; lnum+=6, lcount++) {
  78.     gdev_prn_copy_scan_lines(pdev, lnum, inp = in, line_size * 6);
  79.  
  80.     mask = 0200;
  81.     oldc = 077;
  82.     empty = 1;
  83.  
  84.     for (l = pdev->width, count = 0; --l >= 0; count++) {
  85.         /* transpose 6*8 rectangle */
  86.         register byte *iptr = inp;
  87.         c = 077;
  88.         if (*iptr & mask)
  89.         c += 1;
  90.         if (*(iptr += line_size) & mask)
  91.         c += 2;
  92.         if (*(iptr += line_size) & mask)
  93.         c += 4;
  94.         if (*(iptr += line_size) & mask)
  95.         c += 010;
  96.         if (*(iptr += line_size) & mask)
  97.         c += 020;
  98.         if (*(iptr += line_size) & mask)
  99.         c += 040;
  100.         if (!(mask >>= 1)) {
  101.         mask = 0200;
  102.         inp++;
  103.         }
  104.  
  105.         if (c != oldc) {
  106.         if (empty) {
  107.             while (--lcount >= 0) {
  108. #ifdef VMS
  109.             /* terminate record for VMS STREAM-LF file.
  110.                this LF is ignored by the LN03 */
  111.             fputc('\n', prn_stream);
  112. #endif
  113.             /* terminate previous line */
  114.             fputc('-', prn_stream);
  115.             }
  116.             empty = lcount = 0;
  117.         }
  118.         if (count > 3)
  119.             /* use run length encoding */
  120.             fprintf(prn_stream, "!%d%c", count, oldc);
  121.         else
  122.             while (--count >= 0)
  123.             fputc(oldc, prn_stream);
  124.         oldc = c;
  125.         count = 0;
  126.         }
  127.     }
  128.     if (c != 077) {
  129.         if (count > 3)
  130.         /* use run length encoding */
  131.         fprintf(prn_stream, "!%d%c", count, c);
  132.         else
  133.         while (--count >= 0)
  134.             fputc(c, prn_stream);
  135.     }
  136.     }
  137.  
  138.     /* leave sixel graphics mode, eject page
  139.        <ESC>\        ST    string terminator
  140.        <FF>        FF    form feed */
  141.     fputs("\033\\\f", prn_stream);
  142.     fflush(prn_stream);
  143.  
  144.     gs_free((char *)in, in_size, 1, "ln03_print_page");
  145.  
  146.     return(0);
  147. }
  148.